#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>

int main()
{
	int i, n, s1, j, s2, h;
	long int a, b, t;//写int 错误；写long int 正确；写long long int 时间超限 
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d %d", &a, &b);
		if (a > b) {
			t = a; a = b; b = t;//保证a始终<=b
		}
		s2 = 0;
		for (j = a; j <= b; j++) {
			s1 = 0;
			for (h = 1; h < j; h++) {
				if (j % h == 0)	s1 = s1 + h;//s1用来统计从a-b的每个数j的因数的和(不包括j本身)
			}
			if (s1 == j) s2 = s2 + 1;//s2统计完数的个数
		}
		printf("%d\n", s2);
	}

	return 0;
}//1115完数